﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using DBUtility;
using IDAL.RF.Package;
using Model.RF.Package;

namespace DAL.RF.Package
{
    public class PackintoBox_WithoutUpload : BaseRepository_DT<PackintoBox_WithoutUploadInfo>, IPackintoBox_WithoutUpload
    {
        #region 静态变量部分
        private const string PARM_PACKINTOBOX_ID = "@ID";
        private const string PARM_PACKINTOBOX_RECORDTIME = "@RecordTime";
        private const string PARM_PACKINTOBOX_PRODUCTTYPEID = "@ProductTypeID";
        private const string PARM_PACKINTOBOX_USERID = "@UserID";
        private const string PARM_PACKINTOBOX_AMOUNT = "@Amount";
        private const string PARM_PACKINTOBOX_PCIP = "@PCIP";
        private const string PARM_PACKINTOBOX_REMARK = "@Remark";

        private const string PARM_PACKINTOBOX_DT = "@ProductSNItemdt";
        #endregion


        public bool PackintoBox_WithoutUpload_Insert(PackintoBox_WithoutUploadInfo si, DataTable itemdt)
        {
            List<SqlParameter> ItemList = new List<SqlParameter>() {
            sqlHelper.CreateSqlParemeterStructured(PARM_PACKINTOBOX_DT,itemdt)};
            SqlParameter[] Parms = GetParameters();
            SetParameters(si, Parms);

            SqlCommand cmd = new SqlCommand();
            foreach (SqlParameter parm in Parms)
                cmd.Parameters.Add(parm);
            foreach (SqlParameter parm in ItemList)
                cmd.Parameters.Add(parm);

            using (SqlConnection conn = new SqlConnection(sqlHelper.ConnectionStringLocalTransaction))
            {
                conn.Open();
                cmd.Connection = conn;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "PackintoBox_WithoutUpload_Insert";
                using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { }
                return true;
            }
        }

        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override PackintoBox_WithoutUploadInfo GetEntityRecord(SqlDataReader rdr)
        {
            PackintoBox_WithoutUploadInfo pro = new PackintoBox_WithoutUploadInfo()
            {
                ID = rdr.GetInt32(0),
                RecordTime = rdr.GetDateTime(1),
                ProductTypeID = rdr.GetValue(2).ToString(),
                UserID = rdr.GetValue(3).ToString(),
                Amount = rdr.GetInt32(4),
                PCIP =rdr.GetValue(5).ToString(),
                Remark=rdr.GetValue(6).ToString(),
            };
            return pro;
        }

        public override PackintoBox_WithoutUploadInfo GetEntityRecord()
        {
            PackintoBox_WithoutUploadInfo pro = null;
            return pro;
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_PACKINTOBOX_ID, SqlDbType.Int, 4);
            return Parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_PACKINTOBOX_PRODUCTTYPEID, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_PACKINTOBOX_USERID, SqlDbType.NVarChar, 10),
                    new SqlParameter(PARM_PACKINTOBOX_AMOUNT,SqlDbType.Int,4),
					new SqlParameter(PARM_PACKINTOBOX_PCIP, SqlDbType.NVarChar, 20),
                    new SqlParameter(PARM_PACKINTOBOX_REMARK,SqlDbType.NVarChar, 200)

                };
            return parms;
        }

        public override void SetParameters(PackintoBox_WithoutUploadInfo ad, params SqlParameter[] Parms)
        {
            Parms[0].Value = ad.ProductTypeID;
            Parms[1].Value = ad.UserID;
            Parms[2].Value = ad.Amount;
            Parms[3].Value = ad.PCIP;
            Parms[4].Value = ad.Remark;
        }
        #endregion
    }
}
